package com.yyi.springcloud.controller;


import com.yyi.springcloud.entities.Select2;
import com.yyi.springcloud.entities.SensorNameModel;
import com.yyi.springcloud.service.Local_SensorNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/mysqlapi/SensorNameAPI")
public class Mysql_SensorNameController {
	//按类型注入,不适合多继承
	@Autowired
	private Local_SensorNameService sensorNameService;

	/**
	 * 查询所有的传感器名称 返回select2格式
	 * 
	 * @Description: http://localhost:8080/bxxs/api/SensorNameAPI/
	 *               getAllSensorName
	 * @author 高杨
	 * @date 2018年8月30日 上午9:47:17
	 * @return List<Select2>
	 */
	@ResponseBody
	@RequestMapping(value = "/getAllSensorName", method = RequestMethod.GET)
	public List<Select2> getSensorInfoByCondition() {
		List<SensorNameModel> allSensorName = sensorNameService.getAllSensorName();

		// 将返回结果转换成select2格式
		List<Select2> select2s = new ArrayList<>();
		for (SensorNameModel model : allSensorName) {
			Select2 select2 = new Select2(model.getId(), model.getName().trim());
			select2s.add(select2);
		}
		return select2s;
	}
}
